package com.toogu.mazhangmen.ui.login;

import android.app.Activity;

public class LoginPresenter implements LoginContract.Presenter {
    private LoginModel model;
    private LoginContract.View view;
    private Activity activity;

    public LoginPresenter(Activity activity, LoginContract.View view) {
        this.view = view;
        this.activity=activity;
        model = new LoginModel(activity,this);
    }

    @Override
    public void onLoginFail(String msg) {
        activity.runOnUiThread(()->{
            view.hideProgressBar();
            view.onLoginFail(msg);
        });
    }

    @Override
    public void onLoginSuccess() {
        activity.runOnUiThread(()-> {
            view.onLoginSuccess();
        });
    }

    @Override
    public void login(String userName, String password) {
        activity.runOnUiThread(()-> {
            view.showProgressBar();
            model.login(userName, password);
        });
    }
}
